#include <soar.h>

int main(int argc, char *argv[])
{
    if(argc < 2)
    {
        fprintf(stderr, "usage: %s file\n", argv[0]);
        return(1);
    }

    char *file=argv[1];
    FILE *fp=fopen(file, "r");
    if(!fp)
    {
        fprintf(stderr, "open %s fail\n", file);
        return(1);
    }
    char *content;
    ALLOC_MULTI_DOERR(content, char, BUFFER_SIZE,
            fprintf(stderr, "alloc buffer fail");
            return(1);
            );
    char buf[LONG_NAME_SIZE+1];
    while(fgets(buf, sizeof(buf), fp))
    {
        strcat(content, buf);
    }
    fclose(fp);

    if(encoding_is_utf8(content))
    {
        printf("%s is utf8\n", file);
    }
    else
    {
        printf("%s is NOT utf8\n", file);
    }

    return(0);
}
